function rotate(arr, k) {
    const length = arr.length
    if (k >= length) return arr.reverse()
    return arr.slice(length - k).concat(arr.slice(0, length - k))
}

const nums = [1,2,3,4,5,6,7]
const k = 3
console.log(rotate(nums, k))